import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', name: 'login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true }
]

export const asyncRouterMap = [
  {
    path: '/home',
    component: Layout,
    redirect: '/home/banner/list',
    name: 'home',
    meta: { title: '首页', icon: 'example', roles: ['admin'] },
    children: [
      {
        path: 'banner/list',
        name: 'home-banner-list',
        component: () => import('@/views/home/banner/list'),
        meta: { title: 'banner', icon: 'table' }
      },
      {
        path: 'banner/edit/:id?',
        name: 'home-banner-edit',
        component: () => import('@/views/home/banner/edit'),
        hidden: true,
        meta: { title: '编辑', icon: 'table' }
      },
      {
        path: 'news/list',
        name: 'home-news-list',
        component: () => import('@/views/home/news/list'),
        meta: { title: '新闻', icon: 'table' }
      },
      {
        path: 'news/edit/:id?',
        name: 'home-news-edit',
        component: () => import('@/views/home/news/edit'),
        hidden: true,
        meta: { title: '编辑', icon: 'table' }
      },
      {
        path: 'link/list',
        name: 'home-link-list',
        component: () => import('@/views/home/link/list'),
        meta: { title: '底部链接', icon: 'table' }
      },
      {
        path: 'link/edit/:id?',
        name: 'home-link-edit',
        component: () => import('@/views/home/link/edit'),
        hidden: true,
        meta: { title: '编辑', icon: 'table' }
      }
    ]
  },
  {
    path: '/problems-manager',
    component: Layout,
    redirect: '/problems-manager/problems/list',
    name: 'problems-manager',
    meta: { title: '题目管理', icon: 'example', roles: ['admin'] },
    children: [
      {
        path: 'problems/list',
        name: 'problems-manager-problems-list',
        component: () => import('@/views/problems-manager/problems/list'),
        meta: { title: '添加题目', icon: 'table' }
      },
      {
        path: 'problems/edit/:id?',
        name: 'problems-manager-problems-edit',
        component: () => import('@/views/problems-manager/problems/edit'),
        meta: { title: '添加题目', icon: 'table' },
        hidden: true
      },
      {
        path: 'subject',
        name: 'problems-manager-subject',
        component: () => import('@/views/problems-manager/subject'),
        meta: { title: '添加学科', icon: 'table' }
      },
      {
        path: 'chapter',
        name: 'problems-manager-chapter',
        component: () => import('@/views/problems-manager/chapter'),
        meta: { title: '添加章节', icon: 'table' }
      },
      {
        path: 'type/list',
        name: 'problems-manager-type-list',
        component: () => import('@/views/problems-manager/type/list'),
        meta: { title: '添加题型', icon: 'table' }
      },
      {
        path: 'paper-info',
        name: 'problems-manager-paper-info',
        component: () => import('@/views/problems-manager/paper-info'),
        meta: { title: '添加试卷信息', icon: 'table' }
      }
    ]
  },
  {
    path: '/coursemanagement',
    component: Layout,
    name: 'course',
    meta: { title: '课程管理', icon: 'example', roles: ['admin'] },
    children: [
      {
        path: 'uploadCourse/list',
        name: 'List',
        component: () => import('@/views/coursemanagement/uploadCourse/list'),
        meta: { title: '上传课程', icon: 'table' }
      },
      {
        path: 'uploadCourse/edit/:index?/:page?',
        name: 'uploadEdit',
        component: () => import('@/views/coursemanagement/uploadCourse/edit'),
        meta: { title: '上传课程', icon: 'tree' },
        hidden: true
      },
      {
        path: 'addCourseClassify/list',
        name: 'ClassifyList',
        component: () => import('@/views/coursemanagement/addCourseClassify/list'),
        meta: { title: '添加课程分类', icon: 'tree' },
        hidden: false
      },
      {
        path: 'addCourseClassify/edit/:name?/:examType?',
        name: 'ClassifyEdit',
        component: () => import('@/views/coursemanagement/addCourseClassify/edit'),
        meta: { title: '编辑课程分类', icon: 'tree' },
        hidden: true
      },
      {
        path: 'addSubject/list',
        name: 'subjectList',
        component: () => import('@/views/coursemanagement/addSubject/list'),
        meta: { title: '添加科目', icon: 'tree' },
        hidden: false
      },
      {
        path: 'addSubject/edit/:examType?/:courseCategoryName?/:courseCategoryId?/:name?',
        name: 'SubjectEdit',
        component: () => import('@/views/coursemanagement/addSubject/edit'),
        meta: { title: '编辑科目', icon: 'tree' },
        hidden: true
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    name: 'user',
    meta: { title: '用户管理', icon: 'example', roles: ['admin'] },
    children: [
      {
        path: 'addAccount/list',
        name: 'userList',
        component: () => import('@/views/user/addAccount/list'),
        meta: { title: '账号管理', icon: 'table' },
        hidden: false
      },
      {
        path: 'addAccount/edit/:id?',
        name: 'addAccountEdit',
        component: () => import('@/views/user/addAccount/edit'),
        meta: { title: '添加账号', icon: 'tree' },
        hidden: true
      },
      {
        path: 'distributionCourse/list',
        name: 'distributionCourseList',
        component: () => import('@/views/user/distributionCourse/list'),
        meta: { title: '分配课程', icon: 'table' },
        hidden: false
      },
      {
        path: 'distributionCourse/edit/:id?/:username?/:type?',
        name: 'distributionEdit',
        component: () => import('@/views/user/distributionCourse/edit'),
        meta: { title: '分配课程详情', icon: 'tree' },
        hidden: true
      }
    ]
  },
  { path: '*', redirect: '/login', hidden: true }
]

export default new Router({
  mode: 'history', // 后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})
